package com.spica.platform.user.exception;

import com.spica.platform.base.exception.errorcode.IErrorCode;
import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

public enum SysMenuRtnCodEnum implements IErrorCode {
    UN_KNOWN_SYS_ERROR("UN_KNOW_SYS_ERROR", "未知异常"),
    SYS_MENU_00001("SYS_MENU_00001", "根据菜单id删除菜单操作失败"),
    SYS_MENU_00002("SYS_MENU_00002", "根据菜单id删除菜单操作成功"),
    SYS_MENU_00003("SYS_MENU_00003", "给角色分配菜单操作失败"),
    SYS_MENU_00004("SYS_MENU_00004", "给角色分配菜单操作成功"),
    SYS_MENU_00005("SYS_MENU_00005", "添加菜单或者更新菜单操作失败"),
    SYS_MENU_00006("SYS_MENU_00006", "添加菜单或者更新菜单操作成功"),
    ;

    String rtnCod;
    String rtnMsg;
    SysMenuRtnCodEnum(String rtnCod, String rtnMsg) {
        this.rtnCod = rtnCod;
        this.rtnMsg = rtnMsg;
    }

    @Override
    public String getRtnMessage() {
        return rtnMsg;
    }

    @Override
    public String getRtnCode() {
        return rtnCod;
    }

    @Override
    public IErrorCode getInstanceByErrorCode(String rtnCod) {
        return Arrays.stream(SysMenuRtnCodEnum.values())
                .filter(sysMenuRtnCodEnum -> StringUtil.equals(sysMenuRtnCodEnum.rtnCod, rtnCod))
                .findFirst().orElse(SysMenuRtnCodEnum.UN_KNOWN_SYS_ERROR);
    }
}
